//
//  UserDefaults.swift
//  EyeVisionForPatients
//
//  Created by TT on 2020/2/8.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import Foundation

struct UserDefaultsName {
    static let authToken = "authToken"
    static let userAccount = "userAccount"
    static let videoAccount = "videoAccount"
    static let userPsd = "userPsd"
    static let userId = "userId"
    static let userNick = "userNick"
    static let userAvatar = "userAvatar"
    static let jpushRegistrationId = "jpushRegistrationId"
    static let remberAccountAndPsd = "remberAccountAndPsd"
}

extension UserDefaults {

    // MARK: - 用户登录token

    /// 保存token
    static func saveAuthToken(_ token: String) {
        UserDefaults.standard.set(token, forKey: UserDefaultsName.authToken)
        UserDefaults.standard.synchronize()
    }

    /// 获取token
    static var authToken: String {
        return UserDefaults.standard.string(forKey: UserDefaultsName.authToken) ?? ""
    }
    
    /// 清除token
    static func removeAuthToken() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.authToken)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户名

    /// 用户名
    static var userAccount: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.userAccount) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.userAccount)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户名
    static func removeUserAccount() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.userAccount)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 小鱼云视讯账号

    /// 小鱼云视讯账号
    static var videoAccount: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.videoAccount) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.videoAccount)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除小鱼云视讯账号
    static func removeVideoAccount() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.videoAccount)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户密码

    /// 用户密码
    static var userPsd: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.userPsd) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.userPsd)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户密码
    static func removeUserPsd() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.userPsd)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户ID

    /// 用户ID
    static var userId: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.userId) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.userId)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户ID
    static func removeUserId() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.userId)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户头像

    /// 用户头像
    static var userAvatar: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.userAvatar) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.userAvatar)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户头像
    static func removeUserAvatar() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.userAvatar)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 用户昵称

    /// 用户昵称
    static var userNick: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.userNick) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.userNick)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除用户昵称
    static func removeUserNick() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.userNick)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 极光注册ID

    /// 极光注册ID
    static var jpushRegistrationId: String {
        get { UserDefaults.standard.string(forKey: UserDefaultsName.jpushRegistrationId) ?? "" }
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.jpushRegistrationId)
            UserDefaults.standard.synchronize()
        }
    }

    /// 清除极光注册ID
    static func removeJpushRegistrationId() {
        UserDefaults.standard.removeObject(forKey: UserDefaultsName.jpushRegistrationId)
        UserDefaults.standard.synchronize()
    }

    // MARK: - 是否记住用户名密码

    /// 是否记住用户名密码
    static var remberAccountAndPsd: Bool {
        get { UserDefaults.standard.bool(forKey: UserDefaultsName.remberAccountAndPsd)}
        set {
            UserDefaults.standard.set(newValue, forKey: UserDefaultsName.remberAccountAndPsd)
            UserDefaults.standard.synchronize()
        }
    }

}
